home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH8 / SRC / HILBERT.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-03-06  |  3.5 KB  |  120 lines

  1. VERSION 4.00
  2. Begin VB.Form HilbertForm 
  3.    Caption         =   "Hilbert"
  4.    ClientHeight    =   4335
  5.    ClientLeft      =   2280
  6.    ClientTop       =   1185
  7.    ClientWidth     =   5175
  8.    Height          =   5025
  9.    Left            =   2220
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   289
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   345
  14.    Top             =   555
  15.    Width           =   5295
  16.    Begin VB.TextBox LevelText 
  17.       Height          =   285
  18.       Left            =   600
  19.       MaxLength       =   3
  20.       TabIndex        =   0
  21.       Text            =   "5"
  22.       Top             =   0
  23.       Width           =   375
  24.    End
  25.    Begin VB.PictureBox Canvas 
  26.       AutoRedraw      =   -1  'True
  27.       Height          =   4335
  28.       Left            =   1080
  29.       ScaleHeight     =   285
  30.       ScaleMode       =   3  'Pixel
  31.       ScaleWidth      =   269
  32.       TabIndex        =   3
  33.       Top             =   0
  34.       Width           =   4095
  35.    End
  36.    Begin VB.CommandButton CmdGo 
  37.       Caption         =   "Go"
  38.       Default         =   -1  'True
  39.       Height          =   495
  40.       Left            =   120
  41.       TabIndex        =   1
  42.       Top             =   480
  43.       Width           =   735
  44.    End
  45.    Begin VB.Label Label1 
  46.       Caption         =   "Level"
  47.       Height          =   255
  48.       Index           =   0
  49.       Left            =   0
  50.       TabIndex        =   2
  51.       Top             =   0
  52.       Width           =   495
  53.    End
  54.    Begin VB.Menu mnuFile 
  55.       Caption         =   "&File"
  56.       Begin VB.Menu mnuFileExit 
  57.          Caption         =   "E&xit"
  58.       End
  59.    End
  60. Attribute VB_Name = "HilbertForm"
  61. Attribute VB_Creatable = False
  62. Attribute VB_Exposed = False
  63. Option Explicit
  64. Dim TheLevel As Integer
  65. Dim StartLength As Integer
  66. ' Maximum space the curve can take up.
  67. Dim TotalLength As Integer
  68. Dim StartX As Integer
  69. Dim StartY As Integer
  70. Sub GetParameters()
  71.     If Not IsNumeric(LevelText.Text) Then _
  72.         LevelText.Text = "5"
  73.     TheLevel = CInt(LevelText.Text)
  74.     ' Compute the side length for this level.
  75.     StartLength = TotalLength / (2 ^ TheLevel - 1)
  76. End Sub
  77. Private Sub CmdGo_Click()
  78. Dim i As Integer
  79.     MousePointer = vbHourglass
  80.     DoEvents
  81.     Canvas.Cls
  82.     ' Get the parameters.
  83.     GetParameters
  84.     ' Draw the curve.
  85.     Canvas.CurrentX = StartX
  86.     Canvas.CurrentY = StartY
  87.     Hilbert TheLevel, StartLength, 0
  88.     MousePointer = vbDefault
  89. End Sub
  90. ' ************************************************
  91. ' Draw a hilbert curve.
  92. ' ************************************************
  93. Sub Hilbert(level As Integer, dx As Integer, dy As Integer)
  94.     If level > 1 Then Hilbert level - 1, dy, dx
  95.     Canvas.Line -Step(dx, dy)
  96.     If level > 1 Then Hilbert level - 1, dx, dy
  97.     Canvas.Line -Step(dy, dx)
  98.     If level > 1 Then Hilbert level - 1, dx, dy
  99.     Canvas.Line -Step(-dx, -dy)
  100.     If level > 1 Then Hilbert level - 1, -dy, -dx
  101. End Sub
  102. Private Sub Form_Resize()
  103. Dim unit As Single
  104. Dim vunit As Single
  105. Dim hunit As Single
  106.     Canvas.Move Canvas.Left, 0, _
  107.         ScaleWidth - Canvas.Left, ScaleHeight - 1
  108.     ' See how big we can make the curve.
  109.     If Canvas.ScaleHeight < Canvas.ScaleWidth Then
  110.         TotalLength = 0.9 * Canvas.ScaleHeight
  111.     Else
  112.         TotalLength = 0.9 * Canvas.ScaleWidth
  113.     End If
  114.     StartX = (Canvas.ScaleWidth - TotalLength) / 2
  115.     StartY = (Canvas.ScaleHeight - TotalLength) / 2
  116. End Sub
  117. Private Sub mnuFileExit_Click()
  118.     Unload Me
  119. End Sub
  120.